import request from '@/utils/request';

export interface PostsItem {
  _id: number;
  userID: string;
  content: string;
  title: string;
  tags: string;
}

// 1. 获取标签
export function getPosts(params = {}) {
  return request({
    url: '/posts',
    method: 'post',
    data: params
  });
}

export function addPosts(params: any = {}) {
  const { tags, ...rest } = params;
  const data = {
    ...rest,
    tags: tags && Array.isArray(tags) ? JSON.stringify(tags) : null
  };
  return request({
    url: '/addPosts',
    method: 'post',
    data
  });
}

export function deletePosts(params = {}) {
  return request({
    url: '/deletePosts',
    method: 'post',
    data: params
  });
}

export function updatePosts(params = {}) {
  return request({
    url: '/updatePosts',
    method: 'post',
    data: params
  });
}

export function uploadPosts(params = {}) {
  return request({
    url: '/uploadPosts',
    method: 'post',
    data: params
  });
}
